package service;

import exception.NotEnoughMoneyException;
import repository.WalletEntity;
import repository.WalletRepository;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class WalletService {

    private WalletRepository walletRepository = new WalletRepository();

    public WalletBo getWalletBo(int walletId) {
        WalletEntity walletEntity = walletRepository.getWalletEntity(walletId);
        WalletBo walletBo = new WalletBo(walletEntity.getId(), walletEntity.getBalance(), walletEntity.getFlows(), walletEntity.getFreezeBalance(), walletEntity.getCanOverdraft(), walletEntity.getOverdraftLimit(), walletRepository);
        return walletBo;
    }

    /**
     *  充值功能
     */
    public void recharge(int walletId, double money) { getWalletBo(walletId).recharge(walletId,money); };

    /**
     *  提现功能
     */
    public void withdraw(int walletId, double money) throws NotEnoughMoneyException {
        getWalletBo(walletId).withdraw(walletId, money);
    };

    /**
     *  支付功能
     */
    public void pay(int outWalletId, int inWalletId, double money) throws NotEnoughMoneyException {
       getWalletBo(outWalletId).pay(outWalletId,inWalletId,money);
    };

    /**
     *  查询余额
     */
    public double getBalance(int walletId){
        return getWalletBo(walletId).getBalance(walletId);
    };

    /**
     *  查询交易流水
     */
    public List<String> getFlows(int walletId){
        return getWalletBo(walletId).getFlows(walletId);
    };

    /**
     *  冻结：冻结部分余额
     */
    public void freezeBalance(int walletId, double money) throws NotEnoughMoneyException {
        getWalletBo(walletId).freezeBalance(walletId, money);
    };

    /**
     *  透支：能否透支、透支额度
     */
    public void authorizedOverdraft(int walletId, double limit){
        getWalletBo(walletId).authorizedOverdraft(walletId,limit);
    };
    public void unAuthorizedOverdraft(int walletId){
        getWalletBo(walletId).unAuthorizedOverdraft(walletId);
    };

    /**
     * 更新交易流水
     */
    public void updateFlows(TransactionType transactionType, int walletId, double money){
        getWalletBo(walletId).updateFlows(transactionType, walletId, money);
    }
}

